-
Notifications
You must be signed in to change notification settings - Fork 93
Look at stdout and stderr of k0s etcd member-list separately #938
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Would it be a problem to do it on all versions? It's also possible to get separate streams with something like: var stdoutbuf, stderrbuf bytes.Buffer
cmd, err := h.ExecStreams("command", nil, &stdoutbuf, &stderrbuf, exec.Sudo(h)) // first nil is stdin
if err != nil {
return fmt.Errorf("failed to create command: %w", err)
}
if err := cmd.Wait(); err != nil {
return fmt.Errorf("command failed: %w", err)
}
// parse stdout, maybe log stderr |
Oh, that was the method I was looking for 😅 |
I'm currently experiencing it:
|
Sometimes, random log statements may appear on stderr, which can break the parsing. Try to parse stdout first, then fallback to stderr. Error out if none of both was a JSON document. An example log line on stderr looks like this: W0917 07:11:23.255691 3096 logging.go:55] [core] [Channel k0sproject#1 SubChannel k0sproject#2]grpc: addrConn.createTransport failed to connect to {Addr: "127.0.0.1:2379", ServerName: "127.0.0.1:2379", }. Err: connection error: desc = "transport: Error while dialing: dial tcp 127.0.0.1:2379: operation was canceled" Signed-off-by: Tom Wieczorek <twieczorek@mirantis.com>
0185b51
to
e620285
Compare
result map[string]any | ||
errs []error | ||
) | ||
for _, output := range [][]byte{stdout.Bytes(), stderr.Bytes()} { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe a bit overkill to try parsing stderr for json, but sure, why not
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is for the old k0s versions which write the JSON to stderr.
Sometimes, random log statements may appear on stderr, which can break the parsing. Try to parse stdout first, then fallback to stderr. Error out if none of both was a JSON document.
An example log line on stderr looks like this: